﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLL;
using DAL;
using DevExpress.Skins;
using DevExpress.LookAndFeel;
using DevExpress.UserSkins;
using DevExpress.XtraEditors;
using TTCN_QLDiemC3.MyUserControl.UCHienThi;
using TTCN_QLDiemC3.MyUserControl.UCMenu;

namespace TTCN_QLDiemC3
{
    public partial class Form1 : XtraForm
    {
        String tenGiaoVu=null, Quyen=null;
        public Form1()
        {
            InitializeComponent();
        }

        private void tabPage1_Click(object sender, EventArgs e)
        {

        }

        private void txtUserName_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnDangNhap_Click(object sender, EventArgs e)
        {
            UCHome uchome = new UCHome(tenGiaoVu, Quyen);
            UCDanhSachChucNang ucds = new UCDanhSachChucNang(tenGiaoVu, Quyen);            
            UserBUO userbuo = new UserBUO();
            try
            {
                tenGiaoVu = userbuo.GetSingle(txtUserName.Text).TenGiaoVu;
                Quyen = userbuo.GetSingle(txtUserName.Text).Quyen;
                if (userbuo.CheckUser(txtUserName.Text, txtPassword.Text))
                {
                    grbMenu.Controls.Clear();
                    grbMenu.Controls.Add(uchome);
                    grbHienThiChucNang.Controls.Clear();
                    grbHienThiChucNang.Controls.Add(ucds);

                    //hiển thị các nút
                    pbDiem.Enabled = true;
                    pbGiaoVien.Enabled = true;
                    pbHocSinh.Enabled = true;
                    pbHome.Enabled = true;
                    pbKQHKTheoMon.Enabled = true;
                    pbLop.Enabled = true;
                    pbMonHoc.Enabled = true;
                    pictureBox7.Enabled = true;
                    pictureBox8.Enabled = true;
                    pictureBox9.Enabled = true;       

                }
                else
                {
                    lblThongBao.Text = "Sai username hoặc passwowrd";
                }
            }
            catch (Exception)
            {

                lblThongBao.Text = "Sai username hoặc passwowrd";
            }
        }

        private void pbHome_Click(object sender, EventArgs e)
        {
            UCHome home = new UCHome(tenGiaoVu, Quyen);
            UCDanhSachChucNang ds = new UCDanhSachChucNang(tenGiaoVu, Quyen);
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(home);
            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ds);

        }

        private void pbGiaoVien_Click(object sender, EventArgs e)
        {
            UCChucNangGiaoVien home = new UCChucNangGiaoVien(tenGiaoVu, Quyen);
            UCDanhSachGV ds = new UCDanhSachGV();
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(home);
            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ds);
        }

        private void pbHocSinh_Click(object sender, EventArgs e)
        {
            UCChucNangHocSinh home = new UCChucNangHocSinh(tenGiaoVu, Quyen);
            UCDanhSachHS ds = new UCDanhSachHS();
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(home);
            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ds);
        }

        private void pbMonHoc_Click(object sender, EventArgs e)
        {
            UCChucNangMon home = new UCChucNangMon(tenGiaoVu, Quyen);
            UCDanhSachMon ds = new UCDanhSachMon();
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(home);
            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ds);
        }

        private void pbLop_Click(object sender, EventArgs e)
        {
            UCChucNangLop home = new UCChucNangLop(tenGiaoVu, Quyen);
            UCDanhSachLop ds = new UCDanhSachLop();
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(home);
            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ds);
        }

        private void pbDiem_Click(object sender, EventArgs e)
        {
            UCChucNangBangDiem home = new UCChucNangBangDiem(tenGiaoVu, Quyen);
            UCBangDiem ds = new UCBangDiem();
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(home);
            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ds);
        }

        private void pictureBox7_Click(object sender, EventArgs e)
        {
            UCChucNangThongKe home = new UCChucNangThongKe(tenGiaoVu, Quyen);
            UCThongKeDiemHK ds = new UCThongKeDiemHK();
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(home);
            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ds);
        }

        private void pbKQHKTheoMon_Click(object sender, EventArgs e)
        {
            UCChucNangThongKe home = new UCChucNangThongKe(tenGiaoVu, Quyen);
            UCThongKeDiemHKTheoLop ds = new UCThongKeDiemHKTheoLop();
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(home);
            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ds);
        }

        private void pictureBox9_Click(object sender, EventArgs e)
        {
            UCChucNangThongKe home = new UCChucNangThongKe(tenGiaoVu, Quyen);
            UCThongKeDiemTKCaNam ds = new UCThongKeDiemTKCaNam();
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(home);
            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ds);
        }

        private void pictureBox8_Click(object sender, EventArgs e)
        {
            UCChucNangThongKe home = new UCChucNangThongKe(tenGiaoVu, Quyen);
            UCThongKeDiemTKCaNamTheoMon ds = new UCThongKeDiemTKCaNamTheoMon();
            grbMenu.Controls.Clear();
            grbMenu.Controls.Add(home);
            grbHienThiChucNang.Controls.Clear();
            grbHienThiChucNang.Controls.Add(ds);
        }

        private void txtPassword_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode==Keys.Enter)
            {
                UCHome uchome = new UCHome(tenGiaoVu, Quyen);
                UCDanhSachChucNang ucds = new UCDanhSachChucNang(tenGiaoVu, Quyen);
                UserBUO userbuo = new UserBUO();
                try
                {
                    tenGiaoVu = userbuo.GetSingle(txtUserName.Text).TenGiaoVu;
                    Quyen = userbuo.GetSingle(txtUserName.Text).Quyen;
                    if (userbuo.CheckUser(txtUserName.Text, txtPassword.Text))
                    {
                        grbMenu.Controls.Clear();
                        grbMenu.Controls.Add(uchome);
                        grbHienThiChucNang.Controls.Clear();
                        grbHienThiChucNang.Controls.Add(ucds);

                        //hiển thị các nút
                        pbDiem.Enabled = true;
                        pbGiaoVien.Enabled = true;
                        pbHocSinh.Enabled = true;
                        pbHome.Enabled = true;
                        pbKQHKTheoMon.Enabled = true;
                        pbLop.Enabled = true;
                        pbMonHoc.Enabled = true;
                        pictureBox7.Enabled = true;
                        pictureBox8.Enabled = true;
                        pictureBox9.Enabled = true;

                    }
                    else
                    {
                        lblThongBao.Text = "Sai username hoặc passwowrd";
                    }
                }
                catch (Exception)
                {

                    lblThongBao.Text = "Sai username hoặc passwowrd";
                }
            }
            
        }
    }
}
